<?php
class MissionVo extends SzAbstractMySqlVo
{

    private $userId;
    private $missionId;
    private $conditionsProgress;
    private $drop;
    private $missionUpdateTime;
    private $missionStartTime;
    private $missionEndTime;

    /**
     * Initialize MissionVo.
     *
     * @param $userId
     * @param $missionId
     * @param $conditionsProgress
     * @param $drop
     * @param $missionUpdateTime
     * @param $missionStartTime
     * @param $missionEndTime
     * @param boolean $isInsert default false, means for now this vo is initialized not for insert process
     * @return MissionVo
     */
    public function __construct($userId, $missionId, $conditionsProgress, $drop, $missionUpdateTime, $missionStartTime, $missionEndTime, $isInsert = false) {
        $this->userId = $userId;
        $this->missionId = $missionId;
        $this->conditionsProgress = json_decode($conditionsProgress, true);
        $this->drop = json_decode($drop, true);
        $this->missionUpdateTime = $missionUpdateTime;
        $this->missionStartTime = $missionStartTime;
        $this->missionEndTime = $missionEndTime;

        $this->isInsert = $isInsert;
        $this->voClassName = 'MissionVo';
        $this->ormName = 'Mission';
    }

    /**
     * @see SzAbstractVo::toArray
     */
    public function toArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'missionId' => $this->getMissionId(),
            'conditionsProgress' => ($needEncode) ? $this->getConditionsProgress() : $this->getRawConditionsProgress(),
            'drop' => ($needEncode) ? $this->getDrop() : $this->getRawDrop(),
            'missionUpdateTime' => $this->getMissionUpdateTime(),
            'missionStartTime' => $this->getMissionStartTime(),
            'missionEndTime' => $this->getMissionEndTime(),
        );
    }

    /**
     * @see SzAbstractVo::toEntireArray
     */
    public function toEntireArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'missionId' => $this->getMissionId(),
            'conditionsProgress' => ($needEncode) ? $this->getConditionsProgress() : $this->getRawConditionsProgress(),
            'drop' => ($needEncode) ? $this->getDrop() : $this->getRawDrop(),
            'missionUpdateTime' => $this->getMissionUpdateTime(),
            'missionStartTime' => $this->getMissionStartTime(),
            'missionEndTime' => $this->getMissionEndTime(),
        );
    }

    /**
     * @see SzAbstractVo::toPureArray
     */
    public function toPureArray()
    {
        return array(
            $this->getUserId(),
            $this->getMissionId(),
            $this->getConditionsProgress(),
            $this->getDrop(),
            $this->getMissionUpdateTime(),
            $this->getMissionStartTime(),
            $this->getMissionEndTime(),
        );
    }

    public function getUserId()
    {
        return $this->userId;
    }

    public function setUserId($val)
    {
        $this->saveColumnStatus(0, $this->userId);
        $this->userId = $val;
    }

    public function getMissionId()
    {
        return $this->missionId;
    }

    public function setMissionId($val)
    {
        $this->saveColumnStatus(1, $this->missionId);
        $this->missionId = $val;
    }

    public function getConditionsProgress()
    {
        return json_encode($this->conditionsProgress);
    }

    public function getRawConditionsProgress()
    {
        return $this->conditionsProgress;
    }

    public function setConditionsProgress($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 21840) {
            SzLogger::get()->error('[MissionVo] The length of column conditionsProgress exceed the limit, length / limit: ' . $encodedLength . ' / 21840');
            throw new SzException(10522, array('MissionVo', '21840', $encodedLength));
        } else if ($encodedLength > 19656) {
            SzLogger::get()->warn('[MissionVo] The length of column conditionsProgress exceed the warning level, length / limit: ' . $encodedLength . ' / 21840');
        }
        $this->saveColumnStatus(2, $this->conditionsProgress);
        $this->conditionsProgress = $val;
    }

    public function getDrop()
    {
        return json_encode($this->drop);
    }

    public function getRawDrop()
    {
        return $this->drop;
    }

    public function setDrop($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 21840) {
            SzLogger::get()->error('[MissionVo] The length of column drop exceed the limit, length / limit: ' . $encodedLength . ' / 21840');
            throw new SzException(10522, array('MissionVo', '21840', $encodedLength));
        } else if ($encodedLength > 19656) {
            SzLogger::get()->warn('[MissionVo] The length of column drop exceed the warning level, length / limit: ' . $encodedLength . ' / 21840');
        }
        $this->saveColumnStatus(3, $this->drop);
        $this->drop = $val;
    }

    public function getMissionUpdateTime()
    {
        return $this->missionUpdateTime;
    }

    public function setMissionUpdateTime($val)
    {
        $this->saveColumnStatus(4, $this->missionUpdateTime);
        $this->missionUpdateTime = $val;
    }

    public function getMissionStartTime()
    {
        return $this->missionStartTime;
    }

    public function setMissionStartTime($val)
    {
        $this->saveColumnStatus(5, $this->missionStartTime);
        $this->missionStartTime = $val;
    }

    public function getMissionEndTime()
    {
        return $this->missionEndTime;
    }

    public function setMissionEndTime($val)
    {
        $this->saveColumnStatus(6, $this->missionEndTime);
        $this->missionEndTime = $val;
    }

}